package cn.example.uiwigdets2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.MultiAutoCompleteTextView;
import android.widget.RadioGroup;
import android.widget.ToggleButton;

public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener ,RadioGroup.OnCheckedChangeListener{

    private static final String TAG = "MainActivity";

    private AutoCompleteTextView autoCompleteTextView;
    private MultiAutoCompleteTextView multiAutoCompleteTextView;

    private ImageView img_denpao;
    private ToggleButton swichbutton;

    private RadioGroup rexgx_radio;

    private String [] data=new String[]{"sichuan","sichaun1","sichuan2"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        autoCompleteTextView=findViewById(R.id.my_autoview);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.support_simple_spinner_dropdown_item, data);
        autoCompleteTextView.setAdapter(adapter);
        //
        multiAutoCompleteTextView=findViewById(R.id.my_mul_autoview);
        /* 设置逗号管理器 */
        multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
        multiAutoCompleteTextView.setAdapter(adapter);

        /*   */
        img_denpao= findViewById(R.id.img_dengpao);
        swichbutton = findViewById(R.id.my_switch);
        //监听器
        swichbutton.setOnCheckedChangeListener(this);

        /*  */
        rexgx_radio=findViewById(R.id.rexgx_radio);
        rexgx_radio.setOnCheckedChangeListener(this);


    }

    /*
     事件单元
     */
    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        switch (compoundButton.getId()){
            case R.id.my_switch:
                img_denpao.setImageResource(b?R.drawable.deng1 :R.drawable.deng2);
                break;
        }
    /*
     单选按钮的事件 分发处理
     radioGroup ; 是对按钮组 进行写法.
     */
    }
    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {

        switch (i){
            case R.id.radio1:
                Log.d(TAG, "onCheckedChanged: 男");
                break;
            case R.id.radio2:
                Log.d(TAG, "onCheckedChanged: 女");
                break;
        }
    }
}
